#include <iostream>
using namespace std;
//成员对象1
class MemberObject1{
    public:
    	MemberObject1(int mem1int,int mem1intt);
    	~MemberObject1();
    private:
    	int m_int1;
    	int m_int2;
};
MemberObject1::MemberObject1(int mem1int,int mem1intt):m_int1(mem1int),m_int2(mem1intt){
    cout<<"MemberObject1 build: MemberObject1-array[0]->"<< this->m_int1 
        <<" , MemberObject1-array[1]->"<<this->m_int2<<endl;   
}
MemberObject1::~MemberObject1(){
    cout<<"MemberObject1 destroyed "<<endl;   
}

//成员对象2
class MemberObject2{
    public:
    	MemberObject2(int mem2int);
    	~MemberObject2();
    private:
	    int m_int;
};
MemberObject2::MemberObject2(int mem2int):m_int(mem2int){
    cout<<"MemberObject2 build: MemberObject2-array[0]->"<< this->m_int <<endl;   
}
MemberObject2::~MemberObject2(){
    cout<<"MemberObject2 destroyed "<<endl;   
}

//封闭类
class EnclosedClass{
    public:
    	EnclosedClass(int encint, int obj11, int obj12, int obj21);
    	~EnclosedClass();
    private:
    	int m_int;
    	MemberObject1 obj1;
    	MemberObject2 obj2;
};
EnclosedClass::EnclosedClass(int encint, int obj11, int obj12, int obj21):m_int(encint),obj1(obj11,obj12),obj2(obj21){
    cout<<"EnclosedClass build: EnclosedClass-array[0]->"<< this->m_int <<endl;   
}
EnclosedClass::~EnclosedClass(){
    cout<<"EnclosedClass destroyed "<<endl;   
}

int main(){
    EnclosedClass *env = new EnclosedClass(1,2,3,4);
    delete env;
    env = nullptr; // 避免悬空指针
}